package com.zero.manage.web.components.controller;

import com.zero.manage.web.components.base.BaseController;
import com.zero.manage.web.components.entity.rbac.SysPowerEntity;
import com.zero.manage.web.components.query.SysPowerQuery;
import com.zero.manage.web.components.service.SysPowerService;
import com.zero.manage.web.components.vo.SysPowerVO;
import io.gitee.zerowsh.enums.ToolEnums;
import io.gitee.zerowsh.util.PublicResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/sysPower")
@Api(tags = "系统权限")
public class SysPowerController extends BaseController<SysPowerEntity, String, SysPowerService, SysPowerQuery> {
    @Autowired
    private SysPowerService sysPowerService;

    @RequestMapping(value = "/tree", method = {RequestMethod.POST, RequestMethod.GET})
    @ApiOperation(value = "权限树形接口")
    @ApiImplicitParam(name = "type", value = "权限类型")
    public PublicResult<List<SysPowerVO>> tree(ToolEnums.PowerTypeEnums type) {
        return sysPowerService.tree(type);
    }

    @GetMapping(value = "/getPowerIdsByRoleId")
    @ApiOperation(value = "根据角色编号获取关联权限编号集")
    @ApiImplicitParam(name = "roleId", value = "角色编号", dataType = "String")
    public PublicResult getPowerIdsByRoleId(String roleId) {
        return sysPowerService.getPowerIdsByRoleId(roleId);
    }
}
